package indexingSystem;
import java.io.PrintStream;
import java.util.Vector;

public class Logger {	
	private Vector <String> Error;
	private Vector <String> Report;
	private Vector <String> Message;
	private PrintStream ps = IndexingSystem.getPrintStream();
	private static Logger log = null;
	private boolean verboseMode;
	int errorIndex;
	int messageIndex;
	int reportIndex;
	
	private Logger(){
		Error=new Vector<String>();
		Report=new Vector<String>();
		Message=new Vector<String>();
		verboseMode = true;
		errorIndex = 0;
		messageIndex = 0;
		reportIndex = 0;		
	}
	
	public static Logger getLog(){
		if(log == null)
			return new Logger();
		return log;
	}
	
	public void addError(String msg){
		Error.add(msg);
	}		
	public void addMessage(String msg){
		Message.add(msg);
	}
	public void addReport(String msg){	
		Report.add(msg);			
	}
	
	public void showError(){
		for(int i=0;i<Error.size();i++)
			ps.println(Error.get(i));
	}
	public void showMessage(){
		for(int i=0;i<Message.size();i++)
			ps.println(Message.get(i));
	}
	public void showReport(){
		for(int i=0;i<Report.size();i++)
			ps.println(Report.get(i));
	}
	
	public void showRecentError(){
		for(; errorIndex < Error.size(); errorIndex++)
			ps.println(Error.get(errorIndex));
	}
	public void showRecentMessage(){
		for(; messageIndex<Message.size(); messageIndex++)
			ps.println(Message.get(messageIndex));
	}
	public void showRecentReport(){
		for(; reportIndex < Report.size(); reportIndex++)
			ps.println(Report.get(reportIndex));
	}
	
	public void setVerbose(boolean verbose){ //FIXME Verbose is useless for now
		verboseMode = verbose;
	} 
	public boolean isEmpty(){
		if(Error.size()==0 && Message.size()==0 && Report.size()==0)
			return true;	
		return false;
	}
	
			 
	public void flush(){
		for(int i=0;i<Error.size();i++)
			ps.println(Error.get(i));
		for(int i=0;i<Message.size();i++)	
			ps.println(Message.get(i));
		for(int i=0;i<Report.size();i++)
			ps.println(Report.get(i));
		
		Error.clear();
		Message.clear();
		Report.clear();

		errorIndex = 0;
		reportIndex = 0;
		messageIndex = 0;
	} 
		

}